
package com.szpx.controller.ZJHController;

import com.szpx.entity.ZJH.DriverReservation;
import com.szpx.service.DriverReservationService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * 预定控制器
 */
@Controller
@CrossOrigin
@RequestMapping("/zjh")
public class  ZJHDriverReservationController {
    @Resource
    private DriverReservationService driverReservationService;

    @RequestMapping("/reserve/html")
    public String reserveHtml(HttpSession session, Model model) {
        // TODO: 后续添加订单数据服务注入和数据查询逻辑
//        List<queren> orderList = os.selectAllqueren();
//        model.addAttribute("ol",orderList);
        return "ZJH/reserve.html";
    }


    @RequestMapping("/reserve")
    @ResponseBody
    public Resp reserve(@RequestBody DriverReservation driverReservation) {
        driverReservationService.add(driverReservation);
        return Resp.success();
    }

    @RequestMapping("/getAll")
    @ResponseBody
    public Resp getAll(@RequestBody DriverReservation driverReservation) {
        List<DriverReservation> all = driverReservationService.getAll();
        return Resp.success(all,all.size());
    }

    @RequestMapping("/cancel")
    @ResponseBody
    public Resp cancel(@RequestBody DriverReservation driverReservation) {
        DriverReservation byId = driverReservationService.getById(driverReservation.getId());
        byId.setStatus(DriverReservation.STATUS_CANCELLED);
        driverReservationService.update(byId);
        return Resp.success();
    }

}
